package problems.painteddesert;

import ec.GA;
import ec.Generation;
import ec.Solution;
import ge.BNFGrammarParser;
import ge.CodeEvaluator;
import ge.Expression;
import ge.GESolution;
import ge.NonTerminal;
import ge.ProductionRule;
import ge.standardsymbols.StartSymbol;

import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import org.codehaus.janino.ClassBodyEvaluator;
import org.codehaus.janino.CompileException;
import org.codehaus.janino.Scanner;
import org.codehaus.janino.Parser.ParseException;
import org.codehaus.janino.Scanner.ScanException;

import problems.multiplexer.MultiplexerFitnessEvaluator;

import tests.ge.GrammarTest.DumbIterator;

public class PaintedDesertProblem {
	public static void main(String[] args) throws CompileException,
			ParseException, ScanException, IOException {
		ProductionRule.MAX_DEPTH = 10;
		System.out.println("creating sample expressions");

		int pop_size = 200;
		
		for (int run = 0; run < 30; run++) {
			List<Solution> initial_population = new ArrayList<Solution>(pop_size);
			for (int i = 0; i < pop_size; i++) {
				initial_population.add(new GESolution(
						50 + (int) (Math.random() * 100), 8, .001));
			}

			GA ga = new GA(initial_population, new AntFitnessEvaluator(),
					7, 25, 75, 10);
			
			Generation best_generation = null;
			double best_fitness = Double.NEGATIVE_INFINITY;

			System.out.print("\nRun ");
			System.out.print(run);
			System.out.print(":\n");
			for (int i = 0; i < 40; i++) {
				Generation gen = ga.runGeneration();
				if (gen.getFitnessValue(0) > best_fitness) {
					best_fitness = gen.getFitnessValue(0);
					best_generation = gen;
					System.out.println(best_generation);
				}
				if (best_fitness == 0) {
					System.out.println(best_generation);
				}
			}

		}
	}
}
